<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="css/animate.min.css">
  <style type="text/css">
    .demo-enter,
    .demo-leave-to {
      opacity: 0;
    }

    .demo-enter-active,
    .demo-leave-active {
      transition: opacity 3s;
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- 相当于是舞台剧 -->
    <!-- @before-enter ：动画进场前 参数e 代表被操作的元素-->
    <!-- @enter ：动画表演中  参数e 和回调函数done 代表执行完毕 -->
    <!-- @after-enter ：动画结束表演 参数e 代表被操作的元素 -->
    <!-- 离场动画 把enter 换成 leave -->
    <fade :show='show'>
      <h1>hhhhh</h1>
    </fade>

    <fade :show='show'>
      <h1>66666666666666666666</h1>
    </fade>

    <button @click="handleCLick">切换</button>

  </div>

  <script type="text/javascript" src="js/vue.js"></script>
  <script>
    Vue.component('fade', {
      props: ['show'],
      template: `
      <transition name='demo' @before-enter="handleBeforeEnter" @enter='handleEnter' @after-enter='handleAfterEnter'>
      <slot v-if='show'></slot>
      </transition>

      `,
      methods: {
        handleBeforeEnter(e) {
          e.style.color = 'red'
        },
        handleEnter(e, done) {
          setTimeout(() => {
            e.style.color = 'green'
          }, 2000)
          setTimeout(() => {
            done()
          }, 4000)
        },
        handleAfterEnter(e) {
          e.style.color = 'yellow'

        }
      }
    })
    var vm = new Vue({
      el: '#app',
      data: {
        show: true
      },
      methods: {
        handleCLick() {
          this.show = !this.show
        }
      }
    })
  </script>
</body>

</html>